#include"string.h"


void Test_construct()
{
	string s4("xxxbbb");//string (const char* s)                                      ---第4种构造：直接用char*类型去构造
	string s2(s4);//string (const string& str)                                        ---第2种构造：拷贝构造，传string类型
	string s3(s2, 3,2);//string (const string& str, size_t pos, size_t len = npos)   ---第3种构造：从str的pos位置拷贝len个
	string s5("abcdefg",3);//string (const char* s, size_t n)                        ---第5种构造：把s的前n个拷贝进去
	string s6(4,'a');//string (size_t n, char c)                                     ---第6种构造：拷贝n个c字符
	string s7(s6.begin(), s6.end());//string(InputIterator first, InputIterator last);---第7种构造：范围构造，使用迭代器实现
	cout << "s4:" << s4 << endl;
	cout << "s2:" << s2 << endl;
	cout << "s3:" << s3 << endl;
	cout << "s5:" << s5 << endl;
	cout << "s6:" << s6 << endl;
	cout << "s7:" << s7 << endl;
}
void Test_size_length()
{
	string s = "xxxxxx";
	cout << "size: " << s.size() << endl;
	cout << "length: " << s.length() << endl;
}
void Test_capacity()
{
	string  s("xxxxxxxxxxxxx");
	int pre = s.capacity();
	for (int i = 0; i < 100000; i++)
	{
		s += 'x';
		if (pre < s.capacity())
		{
			cout << "i: " << i << "capacity: " << "增加的字节倍数：" << 1.0*s.capacity()/pre << " " << s.capacity() << endl;
			pre = s.capacity();
		}
	}
}

void Test_resize_reserve()
{
	//string s;
	//cout << "capacity：" << s.capacity() << endl;
	//s.reserve(208);
	//cout << "capacity：" << s.capacity() << endl;
	//s.reserve(15);
	//cout << "capacity：" << s.capacity() << endl;
	//s = "xxxxxxxxxxxxxxxxxxx";//当前字符串长度为20，有效长度，19
	//cout << "capacity：" << s.capacity() << endl;
	//s.reserve(19);//比字符串长度小
	//cout << "capacity：" << s.capacity() << endl;
	//s.reserve(s.capacity()+1);
	//cout << "capacity：" << s.capacity() << endl;

	my_string::string s("xxbbbxxxx");
	my_string::string s1 = s;
	cout << s << " size：" << s.size() << endl;
	//缩小
	s.resize(4);
	cout << s << " size：" << s.size() << endl;

	s = s1;
	cout << s;
	cout << " size：" << s.size() << endl;
	//缩小并改变前面的内容
	s.resize(4,'a');
	cout << s << " size：" << s.size() << endl;

	//增大
	s.resize(8, 'a');
	cout << s << " size：" << s.size() << endl;

	//增大不给初始化值
	s.resize(10);
	cout << s << " size：" << s.size() << endl;
}

void Test_clear()
{
	//string s = "xxxxxxxxxxxxxxxxxxxxxxxxxx";
	//cout << INT_MAX << endl;
	//cout << "size: " << s.size() << "capacity: " << s.capacity() << endl;
	//cout << "max_size" << s.max_size() << endl;
	//s.reserve(200);
	//cout << "size: " << s.size() << "capacity: " << s.capacity() << endl;
	//cout << "max_size" << s.max_size() << endl;
	//s.clear();
	//cout << "size: " << s.size() << "capacity: " << s.capacity() << endl;
	//cout << "max_size" << s.max_size() << endl;

	my_string::string s = "xxxxxxxxxxxxxxxxxxxxxxxxxx";
	cout << "size: " << s.size() << "capacity: " << s.capacity() << endl;
	s.shrink_to_fit();
	cout << "size: " << s.size() << "capacity: " << s.capacity() << endl;
	s.resize(1000,'5');
	cout << "size: " << s.size() << "capacity: " << s.capacity() << endl;
	s.shrink_to_fit();
	cout << "size: " << s.size() << "capacity: " << s.capacity() << endl;
}
void Test_assess()
{
	my_string::string s("xxxxxxbbbb");
	//使用[]访问,故意越界，看是否能检查出来
	for (int i = 0; i <= s.size(); ++i)
	{
		cout << s[i] << " " << endl;
	}

	////使用at函数访问
	//for (int i = 0; i <= s.size(); ++i)
	//{
	//	cout << s.at(i) << " " << endl;
	//}

	//string s("xxxxxxbbbb");
	////使用[]访问,故意越界，看是否能检查出来
	//for (int i = 0; i <= s.size()+1; ++i)
	//{
	//	
	//	cout << s[i] << endl;
	//}

	////使用at函数访问
	//for (int i = 0; i < s.size()+1; ++i)
	//{
	//	s.at(i) = 'c';
	//	cout << s.at(i) << endl;
	//}

	//使用迭代器和范围for访问

	//string s("xxxxxxbbbb");

	////迭代器
	//string::iterator it = s.begin();
	//while (it != s.end())
	//{
	//	cout << *it << endl;
	//	it++;
	//}

	////范围for
	//for (char c : s)
	//{
	//	cout << c << endl;
	//}

	//反向迭代器访问
	//string s("xxxxxxbbbb");
	//auto it = s.rbegin();
	//while (it != s.rend())
	//{
	//	cout << *it << endl;
	//	it++;
	//}
}

void Test_modify()
{
	my_string::string s;
	my_string::string s1("xxxxxx");
	s += 'c';
	s += "1314";
	s += s1;
	cout << s << endl;
}
void Test_append()
{
		string str;
		string str2 = "Writing ";
		string str3 = "print 10 and then 5 more";

		// used in the same order as described above:
		str.append(str2);                       // "Writing "
		str.append(str3, 6, 3);                   // "10 "
		str.append("dots are cool", 5);          // "dots "
		str.append("here: ");                   // "here: "
		str.append(10u, '.');                    // ".........."
		str.append(str3.begin() + 8, str3.end());  // " and then 5 more"
  //           // "....."

		cout << str << '\n';
}

void Test_assign()
{

		std::string str;
		std::string base = "The quick brown fox jumps over a lazy dog.";

		// used in the same order as described above:

		str.assign(base);
		std::cout << str << '\n';

		str.assign(base, 10, 9);
		std::cout << str << '\n';         // "brown fox"

		str.assign("pangrams are cool", 7);
		std::cout << str << '\n';         // "pangram"

		str.assign("c-string");
		std::cout << str << '\n';         // "c-string"

		str.assign(10, '*');
		std::cout << str << '\n';         // "**********"

		
		str.assign(base.begin() + 16, base.end() - 12);
		std::cout << str << '\n';         // "fox jumps over"

	
}

void Test_copy()
{
	//string s = "xxxxxxxbbbbbbbcccccccccxxxx";
	//const char* s2 = s.c_str();
	//cout << s2 << endl;

    string s = "xxxxxxxbbbbbbbcccccccccxxxx";
	char s1[20] = {'\0'};
	s.copy(s1,5, 0);// "xxxxx"
	cout << s1 << endl;
}

void Test_substr()
{
	my_string::string s("love and help");
	cout << s.substr(9,4) << endl;//从s的下标9位置开始的连续4个字符，help
}
void Test_find()
{
	/******************************  find ********************************************/
	string s("xxxxxlovexxxxxlovexxxxlove");
	string str1("lovexxxxxx");
	const char* str2 = "xxl";
	size_t pos1 = s.find(str1,0);//从下标7开始往后找
	if (pos1 != string::npos)
	{
		cout << "找到了!!!!从下标7开始首次出现的位置是" << pos1 << endl;
	}
	else
	{
		cout << "没有找到" << endl;
	}

	size_t pos2 = s.find(str2, 0);//从下标7开始往后找
	if (pos2 != string::npos)
	{
		cout << "找到了!!!!从下标7开始首次出现的位置是" << pos2 << endl;
	}
	else
	{
		cout << "没有找到" << endl;
	}
	/****************************** rfind  ********************************************/
	//string s("xxxxxlovexxxxxlovexxxxlove");
	//string str("lov");
	//size_t pos = s.rfind(str);//从最后的位置开始往回找
	//if (pos != string::npos)
	//{
	//	cout << "找到了!!!!从s的最后一个位置开始首次找到str的位置是" << pos << "找到的字符串为：" << s.substr(pos,str.size()) << endl;
	//}
	//else
	//{
	//	cout << "没有找到" << endl;
	//}
	/****************************** find_first_of  ********************************************/
	/*string str("Please, replace the vowels in this sentence by asterisks.");
	size_t found = str.find_first_of("aeiou");
	while (found != string::npos)
	{
		str[found] = '*';
		found = str.find_first_of("aeiou", found + 1);
	}

	cout << str << '\n';*/
	/******************************   find_last_of   **********************************************************/
	//string str1("c:\\windows\\winhelp.exe");
	//string str2("/usr/bin/man");

	//size_t found1 = str1.find_last_of("/\\");//\\是一个字符
	//cout << "path: " << str1.substr(0, found1) << endl;
	//cout << "file: " << str1.substr(found1+1) << endl;


	//size_t found2 = str2.find_last_of("/\\");//\\是一个字符
	//cout << "path: " << str2.substr(0, found2) << endl;
	//cout << "file: " << str2.substr(found2+1) << endl;

	///****************************** find_first_not_of  ********************************************/
	//string s("I like Ultraman");
	//size_t Found = s.find_first_not_of("I lUik");
	//if (Found != string::npos)
	//{
	//	printf("往后找第一个不在待匹配字符串中的字符为：%c\n", s[Found]);
	//	printf("位置为：%d\n", Found);
	//}

	///****************************** find_last_not_of  ********************************************/
	//string s("I like Ultraman");
	//size_t Found = s.find_last_not_of("manI lUik");
	//if (Found != string::npos)
	//{
	//	printf("往前找第一个不在待匹配字符串中的字符为：%c\n", s[Found]);
	//	printf("位置为：%d\n", Found);
	//}
	//else
	//{
	//	printf("都能找到\n");
	/*}*/
}

void Test_operator()
{


	
		my_string::string firstlevel("com");
		my_string::string secondlevel("cplusplus");
		my_string::string scheme("http://");
		my_string::string hostname;
		my_string::string url;

		hostname = "www." + secondlevel + '.' + firstlevel;
		url = scheme + hostname;

		cout << url << '\n';
}

void Test_compare()
{
	string s = "abc";
	string t = "abf";
	if (s < t)
		cout << "s < t" << endl;
	else
		cout << "s >= t" << endl;
}

void Test_insert_erase()
{
	my_string::string s("xxx");
	my_string::string s1("xxxbbbb");
	s.insert(3, s1);
	cout << s << endl;
	s.insert(s.begin(), '2');
	cout << s << endl;
	s.erase(s.begin());
	cout << s << endl;
	s.erase(s.end());
	cout << s << endl;
	s.erase(0, 4);
	cout << s << endl;
}
//int main()
//{
//	//Test_construct();
//	//Test_size_length();
//	//Test_capacity();
//	//Test_resize_reserve();
//	//Test_clear();
//	//Test_assess();
//	//Test_modify();
//	//int a = 4;
//	//int b = 3;
//	//a += b += 2;
//	//cout << b << " " << a << endl;
//	//Test_append();
//	//Test_assign();
//	//Test_copy();
//	//Test_substr();
//	//Test_find();
//	//Test_insert_erase();
//	//Test_operator();
//	string s("xxxxxxxxx");
//	cout << s.capacity() << endl;
//	s.resize(1200);
//	cout << s.capacity() << endl;
//	s.resize(10);
//	cout << s.capacity() << endl;
//}

int main()
{
	my_string::string s;
	my_string::getline(cin, s);
	cout << s << endl;
}